package com.xmut.bs.handaccount.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.xmut.bs.handaccount.R;
import com.xmut.bs.handaccount.activity.AddArticleActivity;

/**
 * Author Dollkey
 * Date 2018/3/28 13:51.
 */

public class AddPopupWindow extends PopupWindow implements View.OnClickListener {

    private View mParentView;
    private Context mContext;

    public AddPopupWindow(Context context) {
        super(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        mContext = context;
        mParentView = ((Activity) mContext).getWindow().getDecorView().findViewById(android.R.id.content);
        LayoutInflater inflater = LayoutInflater.from(context);
        ViewGroup contentView = (ViewGroup) inflater.inflate(R.layout.pop_add, null);
        contentView.findViewById(R.id.cancel_btn).setOnClickListener(this);
        contentView.findViewById(R.id.article_btn).setOnClickListener(this);
        contentView.findViewById(R.id.video_btn).setOnClickListener(this);

        setBackgroundDrawable(new BitmapDrawable());
        setOutsideTouchable(true);
        setFocusable(true);
        setContentView(contentView);
    }


    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.article_btn) {
            mContext.startActivity(new Intent(mContext, AddArticleActivity.class));
        } else if (i == R.id.video_btn) {
            mContext.startActivity(new Intent(mContext, AddArticleActivity.class));
        }
        dismiss();
    }

    public void show() {
        showAtLocation(mParentView, Gravity.CENTER, 0, 0);
    }
}
